home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
c
/
vbccwossrc.lha
/
vbcc
/
pasm
/
ppcasm.h
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-07
|
24KB
|
658 lines
/* $VER: pasm ppcasm.h V1.2a (16.01.99)
*
* This file is part of pasm, a portable PowerPC assembler.
* Copyright (c) 1997-98 Frank Wille
*
* pasm is freeware and part of the portable and retargetable ANSI C
* compiler vbcc, copyright (c) 1995-98 by Volker Barthelmann.
* pasm may be freely redistributed as long as no modifications are
* made and nothing is charged for it. Non-commercial usage is allowed
* without any restrictions.
* EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
* SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
*
*
* v1.2a (16.01.99) phx
* Compiles on SGI Irix 5.3.
* v1.2 (24.10.98) phx
* @sdarx small data support.
* An empty section with reloc symbols will no longer be deleted.
* v1.1d (27.09.98) phx
* Rudimentary PPC4xx support (contributed by Jeff Bevis - jab).
* Should compile on a (gasp!) Wintel-box.
* v1.1c (22.09.98) phx
* Include file name was trashed.
* v1.1b (05.07.98) phx
* Introduced section flags SF_CHIP and SF_FAST for EHF/ADos. They
* are set by the new section attributes "C" and "F".
* v1.1a (20.06.98) phx
* F_UPDATE. Check rA = rD for update instructions.
* v1.1 (19.06.98) phx
* Multiple small data sections are supported. The new directive
* .sdreg should be used to set the base register.
* Set R_PPC_TOC16 to R_PPC_SDAREL16.
* v1.0 (24.05.98) phx
* Hopefully all known bugs are fixed now and pasm is usable
* on any platform, big endian, little endian and 64-bit.
* Fixed some more bugs in the ELF output file generator and
* some wrong instructions.
* v0.9 (03.04.98) phx
* ELF bug fix: pasm generated WEAK symbols, instead of GLOBAL ones!
* v0.8 (14.02.98) phx
* Alignment list for each section. This fixes the problems
* with optimizations.
* v0.7 (02.01.98) phx
* Define "NetBSDAmiga68k" changed to "NetBSD68k".
* Changed ParsedLine (next) and GlobalVars (anotherpass) to
* allow more than two assembler passes - as required for
* optimizations.
* search_instr() is global.
* Output format 3 is ADOS (like EHF, but doesn't use HUNK_PPC_CODE).
* v0.6 (30.10.97) phx
* More options. GlobalVars: optinstrmode and supermode.
* v0.5 (12.10.97) phx
* Add userdeflist and usrdefs to GlobalVars for symbol definitions
* via the command line.
* .set allows symbols to be reused.
* Last line of a source text was ignored, if newline is missing.
* v0.4 (05.07.97) phx
* Program returns EXIT_FAILURE if an error occurs.
* Base address for absolute code may be set with -B option.
* EHF support.
* Added R_PPC_TOC16 relocation type.
* Option -x automatically declares unknown symbols as
* externally defined. New GlobalVars entry: autoextern.
* Runs on Linux/DEC-Alpha with 64-bit integers.
* Changed program name from "PPCasm" to "pasm". Reason: There
* is already a PPCasm for Apple Macintosh.
* v0.3 (20.04.97) phx
* Using correct names for PowerPC relocations.
* Added little-endian conversion macros.
* v0.2 (25.03.97) phx
* Writes ELF object for 32-bit PowerPC big-endian. Either absolute
* or ELF output format may be selected. ELF is default for all
* currently supported platforms. PPCasm supports nine different
* relocation types (there are much more...).
* Compiles and works also under NetBSD/amiga (68k).
* Changed function declaration to 'new style' in all sources
* (to avoid problems with '...' for example).
* Included NetBSD/amiga as supported architecture.
* v0.1 (11.03.97) phx
* First test version with all PowerPC instructions and most
* important directives. Only raw, absolute output.
* v0.0 (14.02.97) phx
* File created. Project started.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
/* program's name */
#define PNAME "pasm"
/* version/revision */
#define VERSION 1
#define REVISION 2
#define PLEVEL 2
/* architecture specific defines */
#if defined (AmigaOS68k)
#define MACHINE "Amiga OS/M68k"
#define BIGENDIAN
#define STDTYPES
#elif defined (AmigaOSPPC)
#define MACHINE "Amiga OS/PowerPC"
#define BIGENDIAN
#define STDTYPES
#elif defined (NetBSD68k)
#define MACHINE "NetBSD/M68k"
#define BIGENDIAN
#define STDTYPES
#elif defined (SolarisSparc)
#define MACHINE "Solaris/Sparc"
#define BIGENDIAN
#define STDTYPES
#elif defined (SunOSSparc)
#define MACHINE "SunOS/Sparc"
#define BIGENDIAN
#define STDTYPES
#elif defined (SCOi386)
#define MACHINE "SCO/i386"
#define LITTLEENDIAN
#define STDTYPES
#elif defined (Linuxi386)
#define MACHINE "Linux/i386"
#define LITTLEENDIAN
#define STDTYPES
#elif defined (LinuxAlpha)
#define MACHINE "Linux/Alpha"
#define LITTLEENDIAN
#define TYPES64BIT
#elif defined (Wintel) /* jab */
#define MACHINE "Wintel"
#define LITTLEENDIAN
#define STDTYPES
#elif defined (Irix53)
#define MACHINE "Irix5.3/mips"
#define BIGENDIAN
#define STDTYPES
#else
#error Unsupported architecture! Please adapt the source text.
#endif
#ifdef STDTYPES
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int int16;
typedef unsigned short int uint16;
typedef signed long int int32;
typedef unsigned long int uint32;
typedef signed char bool;
#elif defined (TYPES64BIT)
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
typedef signed int int32;
typedef unsigned int uint32;
typedef int bool;
#else
#error Unsupported architecture! Please adapt the source text.
#endif
/* endian conversion */
#if defined (BIGENDIAN)
#define ECH(x) x
#define ECW(x) x
#define ECVH(x) x
#define ECVW(x) x
#elif defined (LITTLEENDIAN)
#define ECH(x) (((x)&0xff)<<8|((x)&0xff00)>>8)
#define ECW(x) (((x)&0xff)<<24|((x)&0xff00)<<8|((x)&0xff0000)>>8|((x)&0xff000000)>>24)
#define ECVH(x) l2bh(x)
#define ECVW(x) l2bw(x)
#else
#error You have to define either BIGENDIAN or LITTLEENDIAN.
#endif
/* program constants */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif
#define FNAMEBUFSIZE 1024 /* buffer size for file names */
#define EXPSTACKSIZE 32 /* maximum arguments in an expression */
/* structures */
struct node {
struct node *next;
struct node *pred;
};
struct list {
struct node *first;
struct node *dummy;
struct node *last;
};
struct CPUInstr {
struct CPUInstr *hash_chain; /* next instruction in hash chain */
char *name; /* instruction's name */
uint16 flags; /* format flags */
uint8 type; /* instruction format, see defines */
uint8 opcd; /* opcode (bit 0-5) */
uint8 fieldD; /* preset D field (bit 6-10) */
uint8 fieldA; /* preset D field (bit 11-15) */
uint16 xo; /* extended opcode (bit 21-31) */
};
/* CPU instruction formats */
#define T_I 0 /* Bx */
#define T_B 1 /* BCx */
#define T_DD 2 /* LWZ */
#define T_DI 3 /* ADDI */
#define T_DS 4 /* LD */
#define T_X 5 /* AND */
#define T_IMM 6 /* MTFSFI */
#define T_XLB 7 /* BCLRx */
#define T_XSPR 8 /* MFSPR */
#define T_XCRM 9 /* MTCRF */
#define T_XFL 10 /* MTFSF */
#define T_XS 11 /* SRADIx */
#define T_A 12 /* FMADDx */
#define T_M 13 /* RLWIMIx */
#define T_MD 14 /* RLDICx */
#define T_CMP 15 /* CMP */
/* CPU instruction flags */
#define F_SUPP_D 0x01 /* D = 0 */
#define F_SUPP_A 0x02 /* A = 0 */
#define F_SUPP_B 0x04 /* B = 0 */
#define F_SUPP_C 0x08 /* C = 0 */
#define F_CRF_D 0x10 /* D = CR field */
#define F_CRF_S 0x20 /* S = CR field */